Class 6 Exam  >  Class 6 Questions  >  What will be the output of the given program?... Start Learning for Free
What will be the output of the given program?
#include<stdio.h>
void main()
{
    int a=11,b=5;
    if(a=5) b++;
    printf("%d %d", ++a, b++);
}
  • a)
    12 7
  • b)
    5 6
  • c)
    6 6
  • d)
    6 7
Correct answer is option 'C'. Can you explain this answer?
Most Upvoted Answer
What will be the output of the given program?#include<stdio.h>vo...
Here if condition evaluates to true as a non-zero value i.e 5 is assigned to a.
So the value of a = 5 and after increment value of b = 6.
In printf statement due to pre-increment of a value of a printed will be 6 and due to post-increment of b value of b printed will be 6 and not 7.
Free Test
Community Answer
What will be the output of the given program?#include<stdio.h>vo...
Explanation:

Initial values:
- a = 11
- b = 5

Condition in if statement:
- The condition in the if statement is (a=5).
- Here, a is assigned the value 5 (a=5) which is a non-zero value, so the condition will be true.
- As a result, the code inside the if statement will be executed.

Code inside the if statement:
- Inside the if statement, b will be incremented by 1 (b++). So, b will become 6.

Output:
- After the if statement, a will be incremented by 1 (++a). So, a will become 12.
- The value of b will be incremented by 1 as well (b++). So, b will become 7.
Therefore, the output of the program will be:

6 6
Explore Courses for Class 6 exam
Question Description
What will be the output of the given program?#include<stdio.h>void main(){ int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);}a)12 7b)5 6c)6 6d)6 7Correct answer is option 'C'. Can you explain this answer? for Class 6 2025 is part of Class 6 preparation. The Question and answers have been prepared according to the Class 6 exam syllabus. Information about What will be the output of the given program?#include<stdio.h>void main(){ int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);}a)12 7b)5 6c)6 6d)6 7Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for Class 6 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What will be the output of the given program?#include<stdio.h>void main(){ int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);}a)12 7b)5 6c)6 6d)6 7Correct answer is option 'C'. Can you explain this answer?.
Solutions for What will be the output of the given program?#include<stdio.h>void main(){ int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);}a)12 7b)5 6c)6 6d)6 7Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Class 6. Download more important topics, notes, lectures and mock test series for Class 6 Exam by signing up for free.
Here you can find the meaning of What will be the output of the given program?#include<stdio.h>void main(){ int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);}a)12 7b)5 6c)6 6d)6 7Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What will be the output of the given program?#include<stdio.h>void main(){ int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);}a)12 7b)5 6c)6 6d)6 7Correct answer is option 'C'. Can you explain this answer?, a detailed solution for What will be the output of the given program?#include<stdio.h>void main(){ int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);}a)12 7b)5 6c)6 6d)6 7Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of What will be the output of the given program?#include<stdio.h>void main(){ int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);}a)12 7b)5 6c)6 6d)6 7Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What will be the output of the given program?#include<stdio.h>void main(){ int a=11,b=5; if(a=5) b++; printf("%d %d", ++a, b++);}a)12 7b)5 6c)6 6d)6 7Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice Class 6 tests.
Explore Courses for Class 6 exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev